package com.example.chain.controller;

import com.example.chain.component.IDecision;
import com.example.chain.component.planB.DecisionService;
import com.example.chain.component.planB.Decsion;
import com.example.chain.dto.DecisionResult;
import com.example.chain.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * web 测试入口
 *
 * @author shixiaodong
 * @date 2022-05-26
 */
@RestController
public class TestController {
    @Resource
    TestService testService;
    @Autowired()
    @Qualifier("time2")
    DecisionService service;
    @Resource
    Map<String, DecisionService> map;
    @Resource
    Map<String, IDecision> map2;

    @GetMapping("/test")
    public DecisionResult test() {
        DecisionResult decisionResult = new DecisionResult();
        testService.decision(decisionResult);
        return decisionResult;
    }

    @GetMapping("/test2")
    public DecisionResult test2() {
        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                Decsion decsion = new Decsion();
                decsion.addChain(map.get("time2"));
                decsion.addChain(map.get("time2"));
                decsion.addChain(map.get("num2"));
                decsion.addChain(map.get("num2"));
                decsion.doNext();
            }).start();
        }
        return new DecisionResult();
    }
}
